package yecq_test2;

import static yecq_test2.main_C.count;
import static yecq_test2.main_C.FULL;
import static yecq_test2.main_C.LOCK;

class Producer implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(3000);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //锁住
            synchronized (LOCK) {
                while (count == FULL) {
                    try {
                        //等待
                        LOCK.wait();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                count++;
                System.out.println(Thread.currentThread().getName() + "生产者生产，生产了个数字" + count);
                //唤醒所有的线程锁
                LOCK.notifyAll();
            }
        }
    }
}
